package JUC;

import java.util.concurrent.CompletableFuture;

public class allof {
        public static void main(String[] args) {
            CompletableFuture<String> future1 = CompletableFuture.supplyAsync(() -> "Result 1");
            CompletableFuture<String> future2 = CompletableFuture.supplyAsync(() -> "Result 2");
            CompletableFuture<String> future3 = CompletableFuture.supplyAsync(() -> "Result 3");

            CompletableFuture<Void> allFutures = CompletableFuture.allOf(future1, future2, future3);

            allFutures.thenRun(() -> {
                System.out.println("All futures completed!");
                System.out.println("Future 1 result: " + future1.join());
                System.out.println("Future 2 result: " + future2.join());
                System.out.println("Future 3 result: " + future3.join());
            });

            // 等待所有CompletableFuture完成
            allFutures.join();
        }
}
